//
//  MLStage1.h
//  WaterProof
//
//  Created by victor0321 on 12/1/3.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "TerminalPipe.h"
#import "RectObject.h"
#import "MLMyParticleSystem.h"
#import "CDAudioManager.h"

// image z order
#define bucket_back -2
#define bucket_front 2
#define pipe_order 1
#define water_order -1

// water emmit
#define emmitOffset 8
#define WATERTAGOFFSET 100

// pipe types
#define pipeA 2400
#define pipeB 1300
#define pipeC 2300
#define pipeD 1200
#define pipeE 1400
#define pipeF 3400
#define pailsmall 1234
#define pailmiddle 2234
#define pailbig 3234
#define left 1
#define up 2
#define right 3
#define down 4
#define leak 5

// grid
#define GRID_MAX_WIDTH 8
#define GRID_MAX_HEIGHT 5
#define RECTSIZE 128
//#define GRID_MAX_WIDTH 16
//#define GRID_MAX_HEIGHT 10
//#define RECTSIZE 64
#define GROW_ANIMATION_DURATION_SECONDS 0.15    
#define SHRINK_ANIMATION_DURATION_SECONDS 0.15
#define RESET_ANIMATION_DURATION_SECONDS 1
#define BOTTOM_DISTANCE 128
int pipeTerminalDir[GRID_MAX_HEIGHT][GRID_MAX_WIDTH];
int pipeTerminalTop[GRID_MAX_WIDTH];
bool isWatterEmmiterTop[GRID_MAX_WIDTH];
bool isWatterEmmiter[GRID_MAX_HEIGHT][GRID_MAX_WIDTH];
int waterEmmiterTag[GRID_MAX_HEIGHT][GRID_MAX_WIDTH];
int waterEmmiterTopTag[GRID_MAX_WIDTH];
int bucketWaterNumber[GRID_MAX_WIDTH]; // save water number
int bucketSize[GRID_MAX_WIDTH];
bool leakWaterLocation[GRID_MAX_WIDTH];
bool leakWaterFlag[GRID_MAX_WIDTH];



@interface MLGrid : CCLayer {
    CGSize screenSize;
    bool hasBucket[GRID_MAX_HEIGHT][GRID_MAX_WIDTH];
    int pipeLocation[GRID_MAX_HEIGHT][GRID_MAX_WIDTH];  // store objects in grid
    int pipeRoute[GRID_MAX_HEIGHT][GRID_MAX_WIDTH];     // store the route
   // NSMutableArray *rectArray;                          // store grid property
   // RectObject *rectObject;                             // tmp object
    ALuint waterSoundID;
    bool isWaterSoundOn;
    CCSprite* grid[GRID_MAX_HEIGHT][GRID_MAX_WIDTH];    // store grid image
    CCSprite* bucketFront[GRID_MAX_HEIGHT][GRID_MAX_WIDTH];
    CCSprite* bucketBack[GRID_MAX_HEIGHT][GRID_MAX_WIDTH];
    int MLGridFloorKickNum;
    CCSprite* soundState;

}
-(void) setBucketImage:(int) bucketTag locaitonx:(int) x locationx:(int)y;
-(void) setBucketWaterFullImage:(int)bucketTag locaitonx:(int)x;
-(bool) setGridImage:(int) imageTag location:(CGPoint)position;
-(void) showGrid;
-(void) hiddenGrid;
-(void) startCheckRoute;
-(void) runWaterEffect:(NSInteger)x locationy:(NSInteger)y index1:(NSInteger)idxx index2:(NSInteger)idxy emmiterTag:(NSInteger)WaterTag;
-(void) runWaterEffect2:(NSInteger)x locationy:(NSInteger)y index1:(NSInteger)idxx emmiterTag:(NSInteger)WaterTag;
-(void) runLeakEffect:(NSInteger)x locationy:(NSInteger)y index1:(NSInteger)idxx emmiterTag:(NSInteger)WaterTag;
-(void) setWaterEffect;
-(void) changeBucketState;
-(void) checkSound;
-(int) getMLGridFloorKickNum;
//-(void) setleakWaterLocation:(NSInteger) x;
-(void) setSoundState;
@end
